/*!
    \copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \addtogroup le_bap
    \brief      Audio contexts handling for PACS profile
    @{
*/

#ifndef PACS_AUDIO_CONTEXTS_H_
#define PACS_AUDIO_CONTEXTS_H_

#include <bdaddr.h>
#include <bt_types.h>

typedef struct
{
    uint16 sink;
    uint16 source;
} audio_contexts_config_t;

/*! \brief PACS utilities instance intialization */
void PacsAudioContexts_InstanceInit(void);

/*! \brief Reset PACS utilities instance */
void PacsAudioContexts_InstanceReset(void);

/*! \brief Gets an instance by CID or creates the instance when the instance is not found for provided cid

    \param cid The GATT connection id for which instance is required.

    \return TRUE if successfully created, otherwise FALSE
*/
bool PacsAudioContexts_InstanceCreate(gatt_cid_t cid);

/*! \brief Updates the old cid with new cid.

    \param old_cid The old GATT connection id
    \param new_cid The new GATT connection id

    \return TRUE if successfully created, otherwise FALSE
*/
bool PacsAudioContexts_UpdateCid(gatt_cid_t old_cid, gatt_cid_t new_cid);

/*! \brief Destroys the instance associated with the CID.

    \param cid The GATT connection id for which instance needs to be destroyed
*/
void PacsAudioContexts_DestroyInstanceForCid(gatt_cid_t cid);

/*! \brief Sets the selective audio context for the instance. If instance is not created for the provided cid,
           creates the instance and sets the avaialable audio context.

    \param cid The GATT connection id for which instance.

    \param audio_contexts_config_t Pointer to audio contexts, which needs to be set for .

    \return TRUE if success, otherwise FALSE.

    \note This API doesn't sets the selective avaialable audio contexts for the GATT cid. It is only used
          to set the audio contexts locally.
*/
bool PacsAudioContexts_SetAvailableAudioContext(gatt_cid_t cid, audio_contexts_config_t *audio_contexts);

/*! \brief This API is used to disable the default audio context management. Application can use this API to take full
           control of Audio context management.

    \note In case of earbud application, this API should be called from both the buds.
 */
void PacsAudioContexts_DisableDefaultAudioContextManagement(void);

/*! \brief Updates the available audio contexts

    \param audio_contexts available audio contexts to set
 */
void PacsAudioContexts_UpdateAvailableAudioContexts(audio_contexts_config_t audio_contexts);

/*! \brief Updates the supported audio contexts

    \param audio_contexts supported audio contexts to set
 */
void PacsAudioContexts_UpdateSupportedAudioContexts(audio_contexts_config_t audio_contexts);

/*! \brief This API is used to set selective "Available Audio Contexts" values for SINK and SOURCE context to notify
           a remote connected client identified by 'device address'. The values of Sink/Source Available Audio Contexts
           should be selected  from the list of Supported Audio Contexts values. The supported audio context can be
           fetched by using LeBapPacsUtilities_GetSinkSupportedAudioContexts() and
           LeBapPacsUtilities_GetSourceSupportedAudioContexts.

    \param cid  The GATT connection id of the handset device for which the available audio context has to be set.
                This could be connected device currently streaming/not streaming. The application can fetch the cid from
                tp_bdaddr using GattConnect_GetConnectionIdFromTpaddr().
    \param sink_audio_contexts    Bitmask of audio data Context Type values for Sink
    \param source_audio_contexts  Bitmask of audio data Context Type values for Source
    \return TRUE if succesfully set the selective audio context, FALSE in case of failure.

    \note : a) The application can handle these messages for LEA streaming (LE_AUDIO_UNICAST_ENABLED/
               LE_AUDIO_UNICAST_DISABLED_IND) to set the selective available audio context for LEA device.
            b) The above unicast streaming messages will contain connection id of the handset device, streaming audio
               context, the audio source which enabled/disabled the unicast stream, such that application shall have all
               relevant information of the LEA source which are streaming. The application can make use of these
               information and set the avaialable audio context as required.
            c) The application can handle these messages for HFP and A2dp (APP_HFP_SCO_CONNECTED_IND/
               APP_HFP_SCO_DISCONNECTED_IND and AV_STREAMING_ACTIVE_IND/AV_STREAMING_INACTIVE_IND) to set selective
               available audio context for the LEA device.
 */
bool PacsAudioContexts_SetSelectiveAvailableAudioContext(gatt_cid_t cid, uint16 sink_audio_contexts, uint16 source_audio_contexts);

/*! \brief Get the Selective Audio contexts set for the provided GATT connection id.

    \param cid  The GATT connection id for which the selective audio context is required.
    \param audio_context Pointer to audio context where the selective audio context will be copied.

    \return TRUE if successfully copied, otherwise FALSE
*/
bool PacsAudioContexts_GetSelectiveAudioContexts(unsigned cid, audio_contexts_config_t *audio_context);

#endif
